package com.mall.goods.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.goods.mapper.PmsProductAttributeMapper;
import com.mall.model.domain.PmsProductAttribute;
import com.mall.model.vo.CommonPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PmsProductAttributeService {

    @Autowired(required = false)
    private PmsProductAttributeMapper pmsProductAttributeMapper;

    /**
     * 根据分类查询属性列表或参数列表
     *
     * @param cid
     * @param type
     * @param pageNum
     * @param pageSize
     * @return
     */
    public CommonPage list(Integer cid, Integer type, Integer pageNum, Integer pageSize) {
        Page<PmsProductAttribute> pageInfo = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<PmsProductAttribute> queryWrapper = new LambdaQueryWrapper<>();
        //查询条件
        queryWrapper.eq(cid != null, PmsProductAttribute::getId, cid);
        queryWrapper.eq(type != null, PmsProductAttribute::getType, type);
        Integer count = pmsProductAttributeMapper.selectCount(queryWrapper);
        pmsProductAttributeMapper.selectPage(pageInfo, queryWrapper);
        return new CommonPage(pageNum, pageSize, count, pageInfo.getRecords());
    }
}
